import request from "@/utils/request";

// 车辆浏览 - 分页列表
export const browseCarList = (params) => request.get("/api/car/browse.do", { params })

// 车辆详情
export const getCarDetail = (id) => request.get("/api/car/detail.do", { params: { id } })

// 获取车辆可租日期
export const getCarAvailability = (carId) => request.get("/api/car/availability.do", { params: { carId } })

// 获取车辆类型列表
export const getCarTypes = () => request.get("/api/car/types.do")

// 收藏相关API
// 添加收藏
export const addToFavorites = (data) => request.post("/api/car/favorite/add.do", data)

// 取消收藏
export const removeFromFavorites = (data) => request.post("/api/car/favorite/remove.do", data)

// 检查收藏状态
export const checkFavoriteStatus = (params) => request.get("/api/car/favorite/check.do", { params })

// 获取用户收藏列表
export const getUserFavorites = (params) => request.get("/api/car/favorite/list.do", { params })


// 商家删除车辆s
export const deleteCar = (params) => request.get("/api/car/deleted.do",{params});
// 商家车辆列表
export const carList = (params) => request.get("/api/car/list.do", { params });

export const insertCar = (obj) => request.post("/api/car/insert.do",obj,{
    headers: { "Content-Type": "application/x-www-form-urlencoded" }
} );

export const updateCar = (params) => {
    const formData = new URLSearchParams()
    Object.keys(params).forEach(key => {
        formData.append(key, params[key] ?? '')
    })
    return request.post("/api/car/update.do", formData, {
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    })
}



